"""
公共方法模块，习惯命名为utils
"""
from time import sleep
from selenium import webdriver


def get_alert_msg():
    sleep(2)
    msg = DriverUtil.get_driver().find_element("class name", "layui-layer-content").text
    return msg


class DriverUtil:
    """浏览器对象管理类"""

    __driver = None

    @classmethod
    def get_driver(cls):
        """获取浏览器对象"""
        if cls.__driver is None:
            cls.__driver = webdriver.Chrome()
            cls.__driver.maximize_window()
            cls.__driver.implicitly_wait(10)
            cls.__driver.get("http://127.0.0.1")
        return cls.__driver

    @classmethod
    def quit_driver(cls):
        """退出浏览器对象"""
        sleep(2)
        cls.__driver.quit()
        cls.__driver = None


if __name__ == '__main__':
    DriverUtil.get_driver()
    DriverUtil.quit_driver()
